package com.springframework.boot.awesome.annotation.arch.runnable;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.CountDownLatch;

public class FlowExecuteRunnable implements Runnable {
    private Method method;
    private Object object;
    private CountDownLatch countDownLatch;

    public FlowExecuteRunnable(Method method, Object object, CountDownLatch countDownLatch) {
        this.method = method;
        this.object = object;
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void run() {
        Object[] params = new Object[]{};
        try {
            method.invoke(object, params);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        countDownLatch.countDown();
    }
}
